package cn.tmpan.service.impl;

import cn.tmpan.common.ServerResponse;
import cn.tmpan.dao.MsgRecordMapper;
import cn.tmpan.entity.MsgRecord;
import cn.tmpan.service.INotifyService;
import cn.tmpan.util.RadomStrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("iNotifyService")
public class INotifyServiceImpl implements INotifyService {
    @Autowired MsgRecordMapper msgRecordMapper;

    /**
     * 发送验证码
     * @param target 手机
     * @param id 发送者uid
     * @return
     */
    @Override
    public ServerResponse SendSmsCheckCode(String target, Integer id) {
        String code = RadomStrUtil.getRandomStr(4).toLowerCase();

        boolean status = sendSms(target,code);

        MsgRecord record = new MsgRecord();
        record.setCheckType(1);
        record.setCode(code);
        record.setSendTarget(target);
        record.setUid(id);
        if (status) record.setResultCode(1);
        else record.setResultCode(2);
        msgRecordMapper.insert(record);


        if(status){
            return ServerResponse.createBySuccessData(code);
        }else{
            return  ServerResponse.createByErrorMessage("发送验证码失败");
        }
    }

    /**
     * 发送短信验证码实现
     * @param target
     * @param code
     * @return
     */
    public boolean sendSms(String target,String code){


        return  true;
    }

}
